package com.example.test06thread.threads;

import com.example.test06thread.util.ThreadLocalUtil;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author: fxy
 * @Date: 2022/05/24/16:40
 * @Description:
 */
public class Test1 {
    public static void main(String[] args) {
        Test1 test1 = new Test1();
        ExecutorService executorService = Executors.newFixedThreadPool(2);
        Map<String,String> map = new HashMap(2);
        ThreadLocalUtil.set("s","8",true);
        map.put("111111111111111111111","111111111111111111111111");
        map.put("222222222222222222222","222222222222222222222222");
        for (String s:map.keySet()) {

            CompletableFuture.runAsync(() -> test1.print(s),executorService);
        }
    }

    public void print(String s){

        System.out.println(Thread.currentThread() + "==========================================="+(s));
       ThreadLocalUtil.set("s",s,true);
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread() + "========================" + ThreadLocalUtil.get("s",true)+"==================="+(s));
    }
}
